<%@ page language="java" pageEncoding="utf-8" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <base href="<%=basePath%>">

    <title>${sessionScope.topicName} - 观点 - ${tag}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <%@include file="im.jsp" %>
    <link rel="stylesheet" href="css/pagination.css"/>
    <link rel="stylesheet" href="css/subPage.css"/>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.pagination.js"></script>

    <script type="text/javascript">
        $(function () {
            var groupName = "<%= request.getParameter("group")%>";
            if (groupName == "person") {
                $("#hotinfo").html("热门发言人");
            } else if (groupName == "newstitle") {
                $("#hotinfo").html("热门观点新闻");
            } else if (groupName == "newssite") {
                $("#hotinfo").html("热门观点网站");
            }


            var initPagination = function () {
                num_entries = $("#hiddenresult>div.result").length;
                // 创建分页
                page = 1; //!!!!!!每页个数！！！！！！
                $("#Pagination").pagination(num_entries, {
                    num_edge_entries: 2, //边缘页数
                    num_display_entries: 6, //主体页数
                    callback: pageselectCallback,
                    items_per_page: page, //每页显示1项
                    prev_text: "前一页",
                    next_text: "后一页"
                });
            }();

            function pageselectCallback(page_index, jq) {
                //alert("IIIII");
                var max_elem = Math.min((page_index + 1) * page, num_entries);
                $("#Searchresult").empty();
                for (var i = page_index * page; i < max_elem; i++) {
                    $("#Searchresult").append(
                            $("#hiddenresult>div.result:eq(" + i + ")").clone());
                }
                ajaxFocus();
                return false;
            }

            function ajaxFocus() {
                $(".favorite").click(function () {
                    var aID = $(this).attr("id");
                    var articleObject = $(this);
                    if ($(this).attr("src") == "images/selected.png") {
                        $.ajax({
                            type: "POST",
                            url: "ajax.jsp",
                            data: "articleID=" + aID + "&operation=delete",
                            beforeSend: function () {
                                //alert("数据处理中...");
                            },
                            success: function (msg) {
                                //alert(msg);
                                articleObject.attr("src", "images/unselected.png");
                                articleObject.attr("alt", "我关注");
                            },
                            error: function (xhr, type, exception) {
                                alert("对不起，出错了！");
                            }
                        });
                    } else {

                        $.ajax({
                            type: "POST",
                            url: "ajax.jsp",
                            data: "articleID=" + aID + "&operation=add",
                            beforeSend: function () {
                                //alert("数据处理中...");
                            },
                            success: function (msg) {
                                //alert(msg);
                                articleObject.attr("src", "images/selected.png");
                                articleObject.attr("alt", "取消\"关注\"");
                            },
                            error: function (xhr, type, exception) {
                                alert("对不起，出错了！");
                            }
                        });
                    }
                });
            }

        });
    </script>

</head>

<body>
<logic:equal name="user" value="administrator">
    <div id="content" class="container">
        <%@include file="top.jsp" %>
        <div class="row">
            <%@include file="left.jsp" %>


            <div class="col-md-10">
                <div>

                    <div>
                        <ul class="nav nav-pills nav-justified">
                            <li><a href="viewAction.do?method=newest">最新观点</a></li>
                            <li><a href="viewGroupAction.do?method=viewgroup&group=person">按人物</a></li>
                            <li><a href="viewGroupAction.do?method=viewgroup&group=newstitle">按新闻</a></li>
                            <li><a href="viewGroupAction.do?method=viewgroup&group=newssite">按站点</a></li>
                        </ul>
                    </div>
                    <div style="margin-bottom:5px;margin-left: 3px;padding-bottom: 5px; border-bottom: 1px dashed darkgray;">
                    </div>
                    <ol class="breadcrumb">
                        <li class="diabled"><<%=request.getAttribute("tag")%>
                        </li>
                        <li class="diabled"><span id="hotinfo"></span></li>
                    </ol>

                    <!-- 这里列出所有的分组名称 -->
                    <div>


                        <logic:present name="result" scope="request">
                            <logic:iterate id="vr" name="result">
                                <logic:greaterThan name="vr" property="count" value="4">
                                    <logic:equal name="vr" property="groupType" value="person">
                                        <html:link page="/viewAction.do?method=newest1&groupType=person"
                                                   paramId="groupName"
                                                   paramName="vr" paramProperty="groupName">
                                            <div class="result" style="display: inline-block; ">
												<span style="color: blue;">
                                                    <bean:write name="vr"
                                                                property="groupName"/> </span> <span> (<bean:write
                                                    name="vr" property="count"/>) </span>
                                            </div>
                                        </html:link>&nbsp;&nbsp;
                                    </logic:equal>
                                    <logic:equal name="vr" property="groupType" value="newstitle">
                                        <html:link page="/viewAction.do?method=newest1&groupType=newstitle"
                                                   paramId="groupName" paramName="vr" paramProperty="groupName">
                                            <div class="result" style="display: inline-block; ">
												<span style="color: blue;"> <bean:write name="vr"
                                                                                        property="groupName"/> </span> <span> (<bean:write
                                                    name="vr" property="count"/>) </span>
                                            </div>
                                        </html:link>
                                    </logic:equal>
                                    <logic:equal name="vr" property="groupType" value="newssite">
                                        <html:link page="/viewAction.do?method=newest1&groupType=newssite"
                                                   paramId="groupName" paramName="vr" paramProperty="groupName">
                                            <div class="result" style="display: inline-block; ">
												<span style="color: blue;"> <bean:write name="vr"
                                                                                        property="groupName"/> </span> <span> (<bean:write
                                                    name="vr" property="count"/>) </span>
                                            </div>
                                        </html:link>
                                    </logic:equal>
                                </logic:greaterThan>
                            </logic:iterate>
                        </logic:present>
                        <div id="Pagination" class="pull-right">
                            <!-- 这里显示分页 -->
                        </div>
                    </div>

                    <div id="Searchresult">分页初始化完成后这里的内容会被替换。</div>
                    <div id="hiddenresult" style="display: none;">
                        <logic:present name="result" scope="request">
                            <logic:iterate id="vr" name="result">
                                <div class="result"
                                     style="display: inline-block;border: solid 1px gray; padding: 8px;">
									<span style="color: blue;"> <bean:write name="vr"
                                                                            property="groupName"/> </span> <span> (<bean:write
                                        name="vr" property="count"/>) </span>

                                    <div>
                                        <logic:iterate id="newest" name="vr" property="viewList"
                                                       type="org.whuims.pois.model.View">
                                            <div class="result">
                                                <logic:notEqual name="vr" property="groupType" value="person">
													<span style="color: blue;"> <bean:write name="newest"
                                                                                            property="cName"/>
													</span>
                                                </logic:notEqual>
                                                &nbsp;&nbsp;&nbsp;&nbsp;
												<span style="font-size: 0.9em;float: right;">
													<logic:notEqual name="vr" property="groupType" value="title">
                                                        <html:link page="/logAction.do" paramId="link"
                                                                   paramName="newest" paramProperty="url"
                                                                   target="_blank">
                                                            <logic:notEqual name="newest" property="title" value="">
                                                                <bean:write name="newest" property="title"
                                                                            filter="true"/>
                                                            </logic:notEqual>
                                                            <logic:equal name="newest" property="title"
                                                                         value="">暂无标题</logic:equal>
                                                        </html:link>
                                                    </logic:notEqual>
													<span>
													 	<bean:write name="newest" property="time"/>
													</span>
													<logic:notEqual name="vr" property="groupType" value="site">
														<span> 
															<bean:write name="newest" property="site"/>
														</span>
                                                    </logic:notEqual>
												</span>

                                                <div>
                                                    <bean:write name="newest" property="view"/>
                                                </div>
                                                <br/>
                                            </div>
                                        </logic:iterate>
                                    </div>
                                </div>
                            </logic:iterate>
                        </logic:present>
                    </div>


                </div>

            </div>
        </div>
        <!--end of right-->
        <div class="footer">
            <%@ include file="foot.jsp" %>
        </div>
    </div>
</logic:equal>
<logic:empty name="user">
    Access Rejected! Error 404
</logic:empty>
</body>
</html>
